var rootPath = getRootPath();

$(function() {
	
	var callbackUrl = getUrlParam("callbackUrl");//getUrlParam 带转义
	
	$.ajax({
		url : rootPath + "/realNameAuth/dr/1/uid",
		method : "GET",
		success : function(data) {
			if (data.returnCode == '0000') {
				var verify = data.returnObject;
				var checkResult = verify.checkResult;
				var verifySuccessts = verify.verifySuccessts;
				var state = verify.state;
				var typeName = verify.creType == 0 ? "身份证" : verify.creType==1 ?"护照" : "其他"; 
				let tip = '';
				let html = '<div class="card-wapper">' + '<img alt="" src="../../images/auth/verify_success1.png">';
				let content = '<label class="block">' + '<div class="info">真实姓名 ：</div>'
								+ '<div class="search_box">' + verify.realName + '</div>'
								+ '</label> <label class="block">'
								+ '<div class="info">证件类型 ：</div>'
								+ '<div class="search_box">' +  typeName + '</div>'
								+ '</label> <label class="block">'
								+ '<div class="info">证件号 ：</div>'
								+ '<div class="search_box">'+ (verify.creType == 0 ? plusXing(verify.creNum, 3, 4) : verify.creNum) + '</div>' + '</label>';

						switch (state) {
						case 1:
							tip = '<div class="title"><span>正在<icon style="color: #C6180A;">审核中</icon>，工作人员将在3个工作日内完成审核，请耐心等候。</span></div>';
							html += '<label class="status">审核中</label>'
									+ '</div>';
							break;
						case 2:
							tip = '<div class="title"><span>恭喜，您已完成<icon style="color:#2FBEB9">真爱梦想实名认证，</icon>如有信息变动可联系客服（电话：021-33194996）</span></div>';
//							html += '<label class="status #C6180A" style="">审核成功</label>'
							if(verify.isOrgAuth == 1) {
								html += '<label class="status #C6180A" style="width:10rem">审核成功-机构实名</label>'
									+ '</div>';
							} else {
								html += '<label class="status #C6180A">审核成功</label>'
									+ '</div>';
							}
							content +='<div class="commitBtn">'
								+ '<input type="button" class="back" style="display:none;background:#b6b6bb;" value="返回">'
								+ '</div>'
							break;
						case 3:
							tip = '<div class="title"><span>抱歉！您的实名认证信息<icon style="color: #C6180A;">未能通过审核</icon>。原因：' + checkResult + '。请</span> <span class="editVerify" id="editVerify">修改认证</span></div>';
							html = '<div class="card-wapper card-wapper1">'
									+ '<img alt="" src="../../images/auth/verify_fail1.png"> <label class="status" >审核失败</label>'
									+ '</div>';
							content +='<div class="commitBtn">'
								+ '<input type="button" id="modify" value="修改">'
								+ '<input type="button" class="back" style="margin-left:5px;display:none;background:#b6b6bb;" value="返回">'
								+ '</div>'
							break;
						}
				$("#result").prepend(content);
				$("#result").prepend(html);
				$("#result").prepend(tip);
				
				if(callbackUrl){
					$(".back").css("display","unset");
					$(".back").click(function(){
						parent.document.location.href = callbackUrl;
					});
				}else{
					$(".back").css("display","none");
				}
			}
			
			$("#editVerify,#modify").click(function() {
				$.ajax({
					url : rootPath + "/verify/dr/1/uid",
					method : "GET",
					success : function(data) {
						if (data.returnCode == '0000') {
							var way = data.returnObject;
							if (way[0].sort < 10) {
								parent.$("#content").prop("src", "certify.html");
							} else {
								if (way[0].state == 1) {
									layer.alert("官方认证正在审核中,请您耐心等候");
								} else {
									layer.confirm('您已完成官方认证,修改实名信息需要重新进行身份认证,请确认是否修改?',{icon : 3,title : '提示'},function(index) {
										parent.$("#content").prop("src", "certify.html");
										layer.close(index);
									});
								}
							}
						} else {
							parent.$("#content").prop("src", "certify.html");
						}
					},
					error : function(jqXHR,textStatus,errorThrown) {
						layer.alert("error");
					}
				});
			});
		},
		error : function(jqXHR, textStatus, errorThrown) {
			layer.alert("error");
		}
	});
});

function formatData(data) {
	return (data != undefined) ? data : '';
}